<?php
$model = new RegistrationForm;
$formchange = new UserRecoveryForm;
?>
<div class="common whiteBg">
    <div class="formElements">
        <div id="registeractiveID"> 
            <?php
            $form = $this->beginWidget('GxActiveForm', array(
                'id' => 'registrationpop-form',
                'action' => Yii::app()->createUrl('user/registrationpop'),
                'enableClientValidation' => true,
                'clientOptions' => array('validateOnSubmit' => true, 'validateOnChange' => true, 'enableAjaxValidation' => true,),
                'htmlOptions' => array('class' => 'remmarginB'),
                    ));
            ?>							

            <fieldset>
                <div class="col-3">
                    <div class="common">
                        <div class="col col1">
                            <label>Email Address <span class="required">*</span></label>
                            <?php echo CHtml::activeTextField($model, 'username', array('class' => 'field')); ?>
                            <?php echo $form->error($model, 'username'); ?>
                        </div>
                        <div class="col col2">
                            <label>Password<span class="required">*</span></label>
                            <?php echo CHtml::activePasswordField($model, 'password', array('class' => 'field', 'type' => 'password')); ?>
                            <?php echo $form->error($model, 'password'); ?>
                        </div>
                        <div class="clear"></div>
                    </div>
                    <div class="common">
                        <div class="col col1">
                            <label>Confirm Password<span class="required">*</span></label>
                            <?php echo CHtml::activePasswordField($model, 'verifyPassword', array('class' => 'field')); ?>
                            <?php echo $form->error($model, 'verifyPassword'); ?>
                        </div>
                        <div class="clear"></div>
                    </div>
                    <div class="common flatuiPopup">
                        <?php echo CHtml::CheckBox('RegistrationForm[issubscribe]', false, array('value' => '1', 'autocomplete' => 'off')); ?><label>Get updates for all the latest happenings in your city. Sign up for our newsletter</label>
                        <?php echo $form->error($model, 'issubscribe'); ?>
                    </div>                                    

                </div> 
            </fieldset>
            <?php
            echo CHtml::ajaxSubmitButton('Sign Up', CHtml::normalizeUrl(array('/user/user/registrationpop')), array(
                'dataType' => 'json',
                'type' => 'post',
                'success' => 'function(data) {
                        $("#AjaxLoaderLogin").hide();  
                        if(data.status=="success"){
							$("#activationEmail").val(data.email);
							$("#activationID").show();
							$("#registeractiveID").hide();
							$("#changepasswordID").hide();
							$("#forgotpasswordID").hide();
                        } else{
							$.each(data, function(key, val) { 
							$("#"+key+"_em_").text(val);                                                    
							$("#"+key+"_em_").show();
							$("#MakeQuery .common").css("margin-bottom","0px");
                        });
                        }
                    }',
                'beforeSend' => 'function(){                        
                           $("#AjaxLoaderLogin").show();
                      }'
                    ), array('class' => 'btn twoBtn', 'name' => 'yt2', 'id' => 'yt2'));
            ?>
            <?php $this->endWidget(); ?></fieldset><a href="javascript:void(0);" onclick="showLoginregister('login');" class="btn">Already a Member? Login</a><span id="AjaxLoaderLogin" style="display:none;"><img src="<?php echo ThemePath(); ?>/images/ajax-loader-mini.gif"></span>
        </div>

        <div id="activationID" style="display:none;">                          
            <div style="color:#006600;">Please check your e-mail, fill bellow your activation key and activate your account!</div>
            <form id="active" method="post">
                <div class="col col1">
                    <input type="hidden" maxlength="45" id="activationEmail" name="email">
                    <input type="text" maxlength="45" name="activationKey" id="activationKey" class="field" placeholder="Activation Key*">
                                            <!--<input type="text" maxlength="45" name="passwordforlogin" id="passwordforlogin" class="field" placeholder="Password*">-->
                    <div id="activationKey_em_" class="errorMessage" style="display:none;">Activation key is empty or Activation Key is invalid.</div>
                    <div class="clear"></div>
                    <?php
                    echo CHtml::ajaxSubmitButton('Submit', CHtml::normalizeUrl(array('/user/user/activationpop')), array(
                        'dataType' => 'json',
                        'type' => 'post',
                        'success' => 'function(data) {
                        $("#AjaxLoaderLogin").hide();  
                        if(data.status=="activated"){
							$("#txtIdLgnRgr").text("Login");
							$("#loginDivId").show();
							$("#RegisterDivId").hide();
							$("#AjaxLoaderLogin").hide();
							$("#activatestatus").show();
                        } else{
		                   $("#activationKey_em_").show();
						}
                    }',
                        'beforeSend' => 'function(){                        
                           $("#AjaxLoaderLogin").show();
                      }'
                            ), array('class' => 'btn twoBtn', 'name' => 'activatebutton', 'id' => 'activatebutton'));
                    ?><span id="AjaxLoaderLogin" style="display:none;"><img src="<?php echo ThemePath(); ?>/images/ajax-loader-mini.gif"></span>



                </div></form></div>


        <div id="changepasswordID" style="display:none;">                          
            <?php echo CHtml::beginForm(); ?>
            <div class="common whiteBg">
                <div class="lg-col">
                    <?php echo CHtml::beginForm(); ?>
                    <p class="note"><?php echo Yii::t("UserModule.user", 'Fields with <span class="required">*</span> are required.'); ?></p>
                    <div class="errorMessage">
                        <?php echo CHtml::errorSummary($formchange); ?>
                    </div>
                    <fieldset>
                        <div class="common">
                            <div class="col col1">
                                <label>E-mail/ Username <span class="required">*</span></label>
                                <?php echo CHtml::activeTextField($formchange, 'login_or_email', array('class' => 'field')) ?>
                                <div class="errorMessage" id="UserRecoveryForm_login_or_email_em_" style="display:none;"></div>
                            </div>
                            <div class="clear"></div>
                        </div>
                        <?php
                        echo CHtml::ajaxSubmitButton('Submit', CHtml::normalizeUrl(array('/user/user/recoverypop')), array(
                            'dataType' => 'json',
                            'type' => 'post',
                            'success' => 'function(data) {
									$("#AjaxLoaderchangepass").hide();
									if(data.status=="success"){
										$("#forgotpasswordID").show();
										$("#changepasswordID").hide();
									} else{
										$.each(data, function(key, val) { 
										$("#"+key+"_em_").text(val);                                                    
										$("#"+key+"_em_").show();
										$("#changepass").prop("disabled", true);
									});
									}
								}',
                            'beforeSend' => 'function(){      
							           $("#AjaxLoaderchangepass").show();                  
									   $("#changepass").prop("disabled", true);
									   
								  }'
                                ), array('class' => 'btn twoBtn', 'name' => 'changepass', 'id' => 'changepass'));
                        ?><a href="javascript:void(0);" onclick="showLoginregister('login');" class="btn">Already a Member? Login</a>&nbsp;&nbsp;<a href="javascript:void(0);" onclick="showLoginregister('register');" class="btn">Need an account? Sign Up</a><span id="AjaxLoaderchangepass" style="display:none;"><img src="<?php echo ThemePath(); ?>/images/ajax-loader-mini.gif"></span>

                    </fieldset>

                    <?php echo CHtml::endForm(); ?>
                </div>     

            </div>					
        </div>

        <div id="forgotpasswordID" style="display:none;">   
            <p style="color:#006600;" id="successok">Please check your e-mail, fill bellow your activation key and change your password!</p> 
            <p style="color:#FF0000;display:none;" id="failok">Given activation key or password incorrect!</p>   
            <div class="clear"></div>                 
            <form class="remmarginB" id="forgotpassword-form" action="" method="post">			
                <fieldset>
                    <div class="col-3">
                        <div class="common">
                            <div class="col col1">
                                <label>Activation Key <span class="required">*</span></label>
                                <input class="field" name="activation_key" id="activation_key" type="text">                                
                                <div class="errorMessage" id="activation_key_err" style="display:none"></div>                                        
                            </div>
                            <div class="col col2">
                                <label>New Password<span class="required">*</span></label>
                                <input class="field" type="password" name="password" id="password">                                
                                <div class="errorMessage" id="password_err" style="display:none"></div>                                        
                            </div>
                            <div class="clear"></div>
                        </div>
                        <div class="common">
                            <div class="col col1">
                                <label>Confirm Password<span class="required">*</span></label>
                                <input class="field" name="confirm_password" id="confirm_password" type="password">                                
                                <div class="errorMessage" id="confirm_password_err" style="display:none"></div>                                        
                            </div>
                            <div class="clear"></div>
                        </div>
                    </div> 
                </fieldset>
                <?php
                echo CHtml::ajaxSubmitButton('Submit', CHtml::normalizeUrl(array('/user/user/forgotpasswordpop')), array(
                    'dataType' => 'json',
                    'type' => 'post',
                    'success' => 'function(data) {
                        $("#AjaxLoaderLoginforgot").hide();  
						if(data.status=="success"){
							$("#txtIdLgnRgr").text("Login");
							$("#loginDivId").show();
							$("#RegisterDivId").hide();
							$("#AjaxLoaderLogin").hide();
							$("#activatestatus").show();
							parent.$("#MakeQuery_users_id").val(data.uid);
							parent.$("#MakeQuery_name").val(data.name);
							parent.$("#MakeQuery_email").val(data.email);
							parent.$("#makeQId").css("display","none"); 
							parent.$("#makeQIdok").show(); 
							window.parent.$("#makeQIdok").trigger("click");
							var magnificPopup = $.magnificPopup.instance; 
							magnificPopup.close(); 
                        } else{
		                   $("#failok").show();
						   $("#successok").hide();
						}
                    }',
                    'beforeSend' => 'function(){                        
                           var chkvalid = checkvalidation();
							if(chkvalid==false){return false;}
						   $("#AjaxLoaderLoginforgot").show();
                      }'
                        ), array('class' => 'btn twoBtn', 'name' => 'forgotpassmake', 'id' => 'forgotpassmake'));
                ?>


            </form>
            <a href="javascript:void(0);" onclick="showLoginregister('login');" class="btn">Already a Member? Login</a><span id="AjaxLoaderLoginforgot" style="display:none;"><img src="<?php echo ThemePath(); ?>/images/ajax-loader-mini.gif"></span>
        </div>			
        <div class="clear"></div>

    </div>
</div>                
<script type="text/javascript">
    jQuery(document).ready(function() {
        $(".flatuiPopup").fancyfields();
    });
    function checkvalidation(){
        var activation_key_val = $("#activation_key").val();
        var password_val = $("#password").val();
        var confirm_password_val = $("#confirm_password").val();
        if(activation_key_val==""){
            $("#activation_key_err").show();
            $("#activation_key_err").text("Enter activation key");
            $("#successok").hide();
            return false;
        }
        if(password_val==""){
            $("#password_err").show();
            $("#activation_key_err").hide();
            $("#password_err").text("Enter new password");
            $("#successok").hide();
            return false;
        }
        if(password_val.length < 4){
            $("#password_err").show();
            $("#activation_key_err").hide();
            $("#password_err").text("minimal length 4 characters");
            $("#successok").hide();
            return false;
        }
        if(confirm_password_val==""){
            $("#password_err").hide();
            $("#activation_key_err").hide();
            $("#confirm_password_err").show();
            $("#confirm_password_err").text("Enter new password");
            $("#successok").hide();
            return false;
        }
        if(password_val != confirm_password_val){
            $("#password_err").hide();
            $("#activation_key_err").hide();
            $("#confirm_password_err").show();
            $("#confirm_password_err").text("New password and confirm password did not match");
            $("#successok").hide();
            return false;
        }

    }

    function showLoginregister(val){
        if(val=="register"){
            $("#loginDivId").hide();
            $("#forgotpasswordID").hide();
            $("#changepasswordID").hide();
            $("#registeractiveID").show();
            $("#RegisterDivId").show();
            $("#txtIdLgnRgr").text("Register");
        }
        if(val=="changepass"){
            $("#loginDivId").hide();
            $("#RegisterDivId").show();
            $("#activationID").hide();
            $("#registeractiveID").hide();
            $("#changepasswordID").show();
            $("#forgotpasswordID").hide();
            $("#txtIdLgnRgr").text("Forgot Password");
        }
        if(val=="forgot"){
            $("#loginDivId").hide();
            $("#RegisterDivId").show();
            $("#activationID").hide();
            $("#registeractiveID").hide();
            $("#forgotpasswordID").show();
            $("#txtIdLgnRgr").text("Forgot Password");
        }
        if(val=="login"){
            $("#txtIdLgnRgr").text("Login");
            $("#loginDivId").show();
            $("#registeractiveID").hide();
            $("#RegisterDivId").hide();
            $("#activationID").hide();
            $("#forgotpasswordID").hide();
            $("#changepasswordID").hide();
        }
    }

	
</script>